package com.jc.service.uservrtaddress;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.jc.cds.model.CustomUserVrtAddress;
import com.jc.ds.base.service.BaseServiceException;
import com.jc.ds.base.service.BaseServiceImpl;
import com.jc.ds.mapper.BaseCustomMapper;
import com.jc.ds.model.UserVrtAddress;
import com.jc.framework.enums.Booleans;

@Service
public class UserVrtAddressServiceImpl extends BaseServiceImpl<UserVrtAddress, CustomUserVrtAddress, Long> implements UserVrtAddressService {

	@Override
	public BaseCustomMapper<CustomUserVrtAddress, Long> getCustomMapper() {
		return null;
	}

	
	
	public String getUserVrtAddressByUserId(Long out_user_id) {
		
		UserVrtAddress userVrtAddress = new UserVrtAddress();
		userVrtAddress.setUserId(out_user_id);
		List<UserVrtAddress> list = queryAll(userVrtAddress);
		if(CollectionUtils.isNotEmpty(list)) {
			String vrtAdress = null;
			for(UserVrtAddress adress : list) {
				if(adress != null && StringUtils.equals(Booleans.TRUE.getName(), adress.getSelected()) ) {
					vrtAdress = adress.getUserVrtAddress();
					break;
				}
			}
			
			if(StringUtils.isBlank(vrtAdress)) {
				//vrtAdress = list.get(0).getUserVrtAddress();
				throw new BaseServiceException("未设置默认交易VRT地址!,请设置以后再进行交易! ");
			}
			return vrtAdress;
		}else {
			return null;
		}
		
	}
	
	
	public void removeVrtAdressByUserId(Long userId) {
		if(userId == null || userId == 0) throw new BaseServiceException("userId 为空, 无法进行删除 !");
		UserVrtAddress query = new UserVrtAddress();
		query.setUserId(userId);
		List<UserVrtAddress> list = queryAll(query);
		for(UserVrtAddress address : list) {
			remove(address.getId());
		}	
	}
	
	
	
	
	

}
